package com.macro.mall.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.OmsOrderReturnReason;
import com.macro.mall.service.OmsOrderReturnReasonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/** 退货原因管理Controller Created by macro on 2018/10/17. */
@Controller
@Api(tags = "OmsOrderReturnReasonController")
@Tag(name = "OmsOrderReturnReasonController", description = "退货原因管理")
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {
  @Autowired private OmsOrderReturnReasonService orderReturnReasonService;

  @ApiOperation("添加退货原因")
  @RequestMapping(value = "/create", method = RequestMethod.POST)
  @ResponseBody
  public CommonResult create(@RequestBody OmsOrderReturnReason returnReason) {
    int count = orderReturnReasonService.create(returnReason);
    if (count > 0) {
      return CommonResult.success(count);
    }
    return CommonResult.failed();
  }

  @ApiOperation("修改退货原因")
  @RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
  @ResponseBody
  public CommonResult update(
      @PathVariable Long id, @RequestBody OmsOrderReturnReason returnReason) {
    int count = orderReturnReasonService.update(id, returnReason);
    if (count > 0) {
      return CommonResult.success(count);
    }
    return CommonResult.failed();
  }

  @ApiOperation("批量删除退货原因")
  @RequestMapping(value = "/delete", method = RequestMethod.POST)
  @ResponseBody
  public CommonResult delete(@RequestParam("ids") List<Long> ids) {
    int count = orderReturnReasonService.delete(ids);
    if (count > 0) {
      return CommonResult.success(count);
    }
    return CommonResult.failed();
  }

  @ApiOperation("分页查询退货原因")
  @RequestMapping(value = "/list", method = RequestMethod.GET)
  @ResponseBody
  public CommonResult<CommonPage<OmsOrderReturnReason>> list(
      @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
    List<OmsOrderReturnReason> reasonList = orderReturnReasonService.list(pageSize, pageNum);
    return CommonResult.success(CommonPage.restPage(reasonList));
  }

  @ApiOperation("获取单个退货原因详情信息")
  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  @ResponseBody
  public CommonResult<OmsOrderReturnReason> getItem(@PathVariable Long id) {
    OmsOrderReturnReason reason = orderReturnReasonService.getItem(id);
    return CommonResult.success(reason);
  }

  @ApiOperation("修改退货原因启用状态")
  @RequestMapping(value = "/update/status", method = RequestMethod.POST)
  @ResponseBody
  public CommonResult updateStatus(
      @RequestParam(value = "status") Integer status, @RequestParam("ids") List<Long> ids) {
    int count = orderReturnReasonService.updateStatus(ids, status);
    if (count > 0) {
      return CommonResult.success(count);
    }
    return CommonResult.failed();
  }
}
